package com.open.capacity.controller;

import com.github.pagehelper.PageInfo;
import com.open.capacity.common.web.Result;
import com.open.capacity.model.ActivityModel;
import com.open.capacity.model.PageModel;
import com.open.capacity.service.ActivityService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/activity2/data")
public class ActivityController2 {
    @Autowired
    private ActivityService2 activityService2;

    /**
     * @author: 李科
     * @Date: 2021/7/15 14:17
     * @Description:查询活动数据
     */
    @GetMapping("/findByPage")
    public Object findByPage(PageModel pageModel,ActivityModel activityModel) {
        PageInfo<ActivityModel> activitys = activityService2.findByPage(pageModel,activityModel);
        return Result.succeed(activitys, "活动数据查询成功！");
    }

    /**
     *
     * @param pageModel
     * @param activityModel
     * @return
     */
    @GetMapping("/findById")
    public Object findById(Long actiid) {
        ActivityModel activityModel=activityService2.findById(actiid);
        return Result.succeed(activityModel, "当前活动数据查询成功！");
    }

    /**
     *  @author: 李科
     *  @Date: 2021/7/19 14:25
     *  @Description:查询所有活动信息，负责定时任务
     */
    @GetMapping("/findAll")
    public Object findAll(){
        List<ActivityModel> activityModels=activityService2.findAll();
        return Result.succeed(activityModels,"无条件查询成功！");
    }

    /**
     * @author: 李科
     * @Date: 2021/7/15 14:18
     * @Description:添加活动数据
     */
    @PostMapping("/update")
    public Object update(ActivityModel activityModel) {
        activityService2.update(activityModel);
        return Result.succeed("活动数据修改成功！");
    }

    /**
     * @author: 李科
     * @Date: 2021/7/15 14:18
     * @Description:删除所选活动
     */
    @GetMapping("/del")
    public Object del(Long actiid) {
        activityService2.del(actiid);
        return Result.succeed("当前活动删除成功！");
    }

    /**
     * @author: 李科
     * @Date: 2021/7/15 14:19
     * @Description:添加活动
     */
    @PostMapping("/add")
    public Object add(ActivityModel activityModel) {
        activityService2.add(activityModel);
        return Result.succeed("添加活动成功！");
    }
}
